
 <!DOCTYPE HTML>
<html lang="ch">
<head>
  <meta charset="UTF-8">
  
    <title>Gradle使用入门 | Yuan</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="Luo Yuan">
    

    
    <meta name="description" content="Gradle是一个基于Groovy实现的，类似于Ant工具的项目构建文件，其设计目标是用更简单的语法和方式来配置一个项目的构建，而不需要像Ant工具一样那么麻烦 。">
<meta property="og:type" content="article">
<meta property="og:title" content="Gradle使用入门">
<meta property="og:url" content="http://luoyuan800.github.io/2015/07/03/gradle/index.html">
<meta property="og:site_name" content="Yuan">
<meta property="og:description" content="Gradle是一个基于Groovy实现的，类似于Ant工具的项目构建文件，其设计目标是用更简单的语法和方式来配置一个项目的构建，而不需要像Ant工具一样那么麻烦 。">
<meta property="og:locale">
<meta property="article:published_time" content="2015-07-03T09:17:14.000Z">
<meta property="article:modified_time" content="2021-04-30T07:56:17.033Z">
<meta property="article:author" content="Luo Yuan">
<meta name="twitter:card" content="summary">

    
    <link rel="alternative" href="/atom.xml" title="Yuan" type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/img/jacman.jpg">
    
    
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/%02.css">
<link rel="stylesheet" href="/.css">

<meta name="generator" content="Hexo 5.4.0"></head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/logo.png" alt="Yuan" title="Yuan"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="Yuan">Yuan</a></h1>
				<h2 class="blog-motto">一点一滴，积累技术</h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/">Home</a></li>
					
						<li><a href="/archives">Archives</a></li>
					
						<li><a href="/about">About</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:luoyuan800.github.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2015/07/03/gradle/" title="Gradle使用入门" itemprop="url">Gradle使用入门</a>
  </h1>
  <p class="article-author">By
       
		<a href="/about" title="Luo Yuan" target="_blank" itemprop="author">Luo Yuan</a>
		
  <p class="article-time">
    <time datetime="2015-07-03T09:17:14.000Z" itemprop="datePublished"> Published 2015-07-03</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E9%85%8D%E7%BD%AEGradle%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">如何配置Gradle：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%94%A8Gradle-%E6%89%93%E5%8C%85%E9%A1%B9%E7%9B%AE"><span class="toc-number">2.</span> <span class="toc-text">用Gradle 打包项目</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Gradle-%E6%9E%84%E5%BB%BAwar%E9%A1%B9%E7%9B%AE%EF%BC%9A"><span class="toc-number">3.</span> <span class="toc-text">Gradle 构建war项目：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%BB%98%E8%AE%A4%E7%9A%84%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84%EF%BC%9A"><span class="toc-number">3.1.</span> <span class="toc-text">默认的项目结构：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E8%84%9A%E6%9C%AC%E7%A4%BA%E4%BE%8B%EF%BC%9A"><span class="toc-number">3.2.</span> <span class="toc-text">一个简单脚本示例：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%87%E7%AD%BE%E5%90%AB%E4%B9%89%E4%BB%8B%E7%BB%8D"><span class="toc-number">3.3.</span> <span class="toc-text">标签含义介绍</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8gradle%E5%85%B3%E8%81%94%E6%9C%AC%E5%9C%B0%E7%9A%84jar%E5%8C%85"><span class="toc-number">4.</span> <span class="toc-text">使用gradle关联本地的jar包</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#gradle-%E4%B8%AD%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8ant"><span class="toc-number">5.</span> <span class="toc-text">gradle 中直接使用ant</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E7%A7%8D%E6%96%B9%E5%BC%8F%E6%98%AF%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E5%9C%A8gradle%E7%9A%84build%E4%B8%AD%E7%9B%B4%E6%8E%A5%E8%B0%83%E7%94%A8ant%E7%9B%B8%E5%85%B3%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%8C%E6%AF%94%E5%A6%82%EF%BC%9A"><span class="toc-number">5.1.</span> <span class="toc-text">一种方式是可以直接在gradle的build中直接调用ant相关的命令，比如：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B9%9F%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E5%AF%BC%E5%85%A5%E7%8E%B0%E6%9C%89%E7%9A%84antbuild%E6%96%87%E4%BB%B6%EF%BC%88build-xml%EF%BC%89"><span class="toc-number">5.2.</span> <span class="toc-text">也可以直接导入现有的antbuild文件（build.xml）</span></a></li></ol></li></ol>
		
		</div>
		
		<p>Gradle是一个基于Groovy实现的，类似于Ant工具的项目构建文件，其设计目标是用更简单的语法和方式来配置一个项目的构建，而不需要像Ant工具一样那么麻烦 。<span id="more"></span></p>
<h2 id="如何配置Gradle："><a href="#如何配置Gradle：" class="headerlink" title="如何配置Gradle："></a>如何配置Gradle：</h2><ul>
<li><p>下载Gradle解压到自定义文件夹</p>
</li>
<li><p>配置环境变量：GRADLE_HOME</p>
</li>
<li><p>添加%GRADLE_HOME%到Path中</p>
</li>
<li><p>测试 gradle -v 输出正常表示配置成功</p>
</li>
</ul>
<h2 id="用Gradle-打包项目"><a href="#用Gradle-打包项目" class="headerlink" title="用Gradle 打包项目"></a>用Gradle 打包项目</h2><ul>
<li><p>构建 build.gradle 文件</p>
</li>
<li><p>一个简单的gradle build文件</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br></pre></td><td class="code"><pre><span class="line">apply plugin: &#39;java&#39;</span><br><span class="line"></span><br><span class="line">version &#x3D; &#39;1.0.0&#39;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">repositories &#123;</span><br><span class="line"></span><br><span class="line">mavenLocal()</span><br><span class="line"></span><br><span class="line">mavenCentral()</span><br><span class="line"></span><br><span class="line">maven&#123;</span><br><span class="line"></span><br><span class="line">url &quot;https:&#x2F;&#x2F;oosnmp.net&#x2F;dist&#x2F;release&quot;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">dependencies &#123;</span><br><span class="line"></span><br><span class="line">compile &#39;org.snmp4j:snmp4j:2.3.3&#39;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">jar &#123;</span><br><span class="line"></span><br><span class="line">manifest&#123;</span><br><span class="line"></span><br><span class="line">attributes &#39;Title&#39;: &#39;SNMPFramework&#39;, &#39;Version&#39; : 1.0, &#39;Author&#39;:&#39;LuoYuan&#39;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">metaInf &#123;</span><br><span class="line"></span><br><span class="line">from(&#39;..&#39;) &#123;</span><br><span class="line"></span><br><span class="line">include &#39;*.md&#39;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">includeEmptyDirs &#x3D; false</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">sourceSets&#123;</span><br><span class="line"></span><br><span class="line">main &#123;</span><br><span class="line"></span><br><span class="line">java&#123;</span><br><span class="line"></span><br><span class="line">srcDir &#39;src&#39;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">task javaDoces(type: Javadoc)&#123;</span><br><span class="line"></span><br><span class="line">source &#x3D; sourceSets.main.allJava</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这个build文件表示这个项目的依赖关系，还有从什么地方获取依赖包。</p>
<p><strong>dependencies</strong> 标签定义编译代码的时候要依赖的jar包</p>
<p>Gradle会尝试从<strong>repositories</strong>获取依赖的jar包 ，然后放到user/.gradle的文件目录下缓存，下次build的时候直接从这个地方获取。</p>
<p><strong>task</strong> 标签定义一个新的task， 可以通过gradle &lt;task&gt; 运行。</p>
<p><strong>sourceSet</strong>标签指定项目的源代码结果，如果不配置的话会是用默认的结构 src/main/java作为源文件的存放位置。</p>
<p><strong>jar</strong> 标签定义执行build之后生成的jar包目录结构，可以配置jar包中manifest文件的内容。</p>
<p><strong>metaInf</strong> 标签定义在生产的jar包中 META-INF 目录要放入的文件。</p>
<h2 id="Gradle-构建war项目："><a href="#Gradle-构建war项目：" class="headerlink" title="Gradle 构建war项目："></a>Gradle 构建war项目：</h2><h3 id="默认的项目结构："><a href="#默认的项目结构：" class="headerlink" title="默认的项目结构："></a>默认的项目结构：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">.</span><br><span class="line"></span><br><span class="line">├── build.gradle</span><br><span class="line"></span><br><span class="line">└── src</span><br><span class="line"></span><br><span class="line">    └── main</span><br><span class="line"></span><br><span class="line">        ├── java</span><br><span class="line"></span><br><span class="line">        │   └── com</span><br><span class="line"></span><br><span class="line">        │       └── manning</span><br><span class="line"></span><br><span class="line">        │           └── gia</span><br><span class="line"></span><br><span class="line">        │               └── todo</span><br><span class="line"></span><br><span class="line">        │                   ├── model</span><br><span class="line"></span><br><span class="line">        │                   │   └── ToDoItem.java</span><br><span class="line"></span><br><span class="line">        │                   ├── repository</span><br><span class="line"></span><br><span class="line">        │                   │   ├── InMemoryToDoRepository.java</span><br><span class="line"></span><br><span class="line">        │                   │   └── ToDoRepository.java</span><br><span class="line"></span><br><span class="line">        │                   └── web</span><br><span class="line"></span><br><span class="line">        │                       └── ToDoServlet.java</span><br><span class="line"></span><br><span class="line">        └── webapp-------------------------------------------------#A</span><br><span class="line"></span><br><span class="line">            ├── WEB-INF</span><br><span class="line"></span><br><span class="line">            │   └── web.xml----------------------------------------#B</span><br><span class="line"></span><br><span class="line">            ├── css------------------------------------------------#C</span><br><span class="line"></span><br><span class="line">            │   ├── base.css</span><br><span class="line"></span><br><span class="line">            │   └── bg.png</span><br><span class="line"></span><br><span class="line">            └── jsp------------------------------------------------#D</span><br><span class="line"></span><br><span class="line">                ├── index.jsp</span><br><span class="line"></span><br><span class="line">                └── todo-list.jsp</span><br></pre></td></tr></table></figure>

<p>#A Web源文件默认目录</p>
<p>#B Web应用描述符文件</p>
<p>#C 存储描述如何展现HTML元素的样式单文件的目录</p>
<p>#D 存放JSP形式的动态脚本化视图组件</p>
<h3 id="一个简单脚本示例："><a href="#一个简单脚本示例：" class="headerlink" title="一个简单脚本示例："></a>一个简单脚本示例：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">apply plugin: &#39;war&#39;</span><br><span class="line"></span><br><span class="line">version &#x3D; &#39;1.0.0&#39;</span><br><span class="line"></span><br><span class="line">apply plugin: &#39;jetty&#39;</span><br><span class="line"></span><br><span class="line">httpPort &#x3D; 8888</span><br><span class="line"></span><br><span class="line">repositories &#123;</span><br><span class="line"></span><br><span class="line">    mavenLocal()</span><br><span class="line"></span><br><span class="line">    mavenCentral()</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">war &#123;</span><br><span class="line"></span><br><span class="line">    manifest&#123;</span><br><span class="line"></span><br><span class="line">        attributes &#39;Title&#39;: &#39;SNMPFrameworkUI&#39;, &#39;Version&#39; : 1.0, &#39;Author&#39;:&#39;LuoYuan&#39;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">     metaInf &#123;</span><br><span class="line"></span><br><span class="line">         from(&#39;.&#39;) &#123;</span><br><span class="line"></span><br><span class="line">             include &#39;**&#x2F;*.md&#39;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">         includeEmptyDirs &#x3D; false</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="标签含义介绍"><a href="#标签含义介绍" class="headerlink" title="标签含义介绍"></a>标签含义介绍</h3><p><strong>apply plugin:’jetty’</strong> 指定是用jetty作为运行war的容器，当运行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">gradle jettyRun</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>可以启动jetty 然后自动部署当前的war包进行测试。</p>
<p><strong>httpPort</strong> 这个属性指定jetty运行的时候使用的端口，默认为8080。</p>
<h2 id="使用gradle关联本地的jar包"><a href="#使用gradle关联本地的jar包" class="headerlink" title="使用gradle关联本地的jar包"></a>使用gradle关联本地的jar包</h2><ul>
<li>首先定义repositories</li>
</ul>
<p>repositories {</p>
<p>   flatDir{</p>
<pre><code>    dirs &#39;src/main/webapp/WEB-INF/lib&#39;
</code></pre>
<p>}</p>
<p>}</p>
<ul>
<li>然后需要将jar包放到对应的目录，并且在build文件中增加</li>
</ul>
<p>dependencies {</p>
<pre><code>compile ([&#39;:name:version&#39;],[&#39;:name:version&#39;])
</code></pre>
<p>}</p>
<h2 id="gradle-中直接使用ant"><a href="#gradle-中直接使用ant" class="headerlink" title="gradle 中直接使用ant"></a>gradle 中直接使用ant</h2><h3 id="一种方式是可以直接在gradle的build中直接调用ant相关的命令，比如："><a href="#一种方式是可以直接在gradle的build中直接调用ant相关的命令，比如：" class="headerlink" title="一种方式是可以直接在gradle的build中直接调用ant相关的命令，比如："></a>一种方式是可以直接在gradle的build中直接调用ant相关的命令，比如：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">task zip &lt;&lt; &#123;</span><br><span class="line">        ant.zip(destfile: &#39;archive.zip&#39;) &#123;</span><br><span class="line">            fileset(dir: &#39;src&#39;) &#123;</span><br><span class="line">                include(name: &#39;**.xml&#39;)</span><br><span class="line">                exclude(name: &#39;**.java&#39;)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h3 id="也可以直接导入现有的antbuild文件（build-xml）"><a href="#也可以直接导入现有的antbuild文件（build-xml）" class="headerlink" title="也可以直接导入现有的antbuild文件（build.xml）"></a>也可以直接导入现有的antbuild文件（build.xml）</h3><p>可以同时给ant trarget name 加上前缀，这样可以避免出现同名的错误。<br>这个引入的ant 中定义的target放在other的group下面。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ant.importBuild(&#39;build.xml&#39;) &#123; antTargetName -&gt;</span><br><span class="line">  &#39;ant-&#39;+antTargetName</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/categories/%E7%BC%96%E7%A8%8B-%E5%B7%A5%E5%85%B7/">编程-工具</a>
</div>


</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://luoyuan800.github.io/2015/07/03/gradle/" data-title="Gradle使用入门 | Yuan" data-tsina="" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2015/07/06/log4j-extend/" title="Log4J中的继承关系">
  <strong>上一篇：</strong><br/>
  <span>
  Log4J中的继承关系</span>
</a>
</div>


<div class="next">
<a href="/2015/07/01/linux-filesystem/"  title="Linux 文件系统类型">
 <strong>下一篇：</strong><br/> 
 <span>Linux 文件系统类型
</span>
</a>
</div>

</nav>

	



</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E9%85%8D%E7%BD%AEGradle%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">如何配置Gradle：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%94%A8Gradle-%E6%89%93%E5%8C%85%E9%A1%B9%E7%9B%AE"><span class="toc-number">2.</span> <span class="toc-text">用Gradle 打包项目</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Gradle-%E6%9E%84%E5%BB%BAwar%E9%A1%B9%E7%9B%AE%EF%BC%9A"><span class="toc-number">3.</span> <span class="toc-text">Gradle 构建war项目：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%BB%98%E8%AE%A4%E7%9A%84%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84%EF%BC%9A"><span class="toc-number">3.1.</span> <span class="toc-text">默认的项目结构：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E8%84%9A%E6%9C%AC%E7%A4%BA%E4%BE%8B%EF%BC%9A"><span class="toc-number">3.2.</span> <span class="toc-text">一个简单脚本示例：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%87%E7%AD%BE%E5%90%AB%E4%B9%89%E4%BB%8B%E7%BB%8D"><span class="toc-number">3.3.</span> <span class="toc-text">标签含义介绍</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8gradle%E5%85%B3%E8%81%94%E6%9C%AC%E5%9C%B0%E7%9A%84jar%E5%8C%85"><span class="toc-number">4.</span> <span class="toc-text">使用gradle关联本地的jar包</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#gradle-%E4%B8%AD%E7%9B%B4%E6%8E%A5%E4%BD%BF%E7%94%A8ant"><span class="toc-number">5.</span> <span class="toc-text">gradle 中直接使用ant</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E7%A7%8D%E6%96%B9%E5%BC%8F%E6%98%AF%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E5%9C%A8gradle%E7%9A%84build%E4%B8%AD%E7%9B%B4%E6%8E%A5%E8%B0%83%E7%94%A8ant%E7%9B%B8%E5%85%B3%E7%9A%84%E5%91%BD%E4%BB%A4%EF%BC%8C%E6%AF%94%E5%A6%82%EF%BC%9A"><span class="toc-number">5.1.</span> <span class="toc-text">一种方式是可以直接在gradle的build中直接调用ant相关的命令，比如：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B9%9F%E5%8F%AF%E4%BB%A5%E7%9B%B4%E6%8E%A5%E5%AF%BC%E5%85%A5%E7%8E%B0%E6%9C%89%E7%9A%84antbuild%E6%96%87%E4%BB%B6%EF%BC%88build-xml%EF%BC%89"><span class="toc-number">5.2.</span> <span class="toc-text">也可以直接导入现有的antbuild文件（build.xml）</span></a></li></ol></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/categories/杂物-医学/" title="杂物-医学">杂物-医学<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-Java/" title="编程-Java">编程-Java<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-Linux-Unix/" title="编程-Linux/Unix">编程-Linux/Unix<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-工具/" title="编程-工具">编程-工具<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-网络协议/" title="编程-网络协议">编程-网络协议<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/categories/网站-开发/" title="网站-开发">网站-开发<sup>2</sup></a></li>
		  
		
		</ul>
</div>


  

  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=&verifier=&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m Luo Yuan in Zhuhai. <br/>
			Here is my place for knowledge accumulation.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2021 
		
		<a href="/about" target="_blank" title="Luo Yuan">Luo Yuan</a>
		
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.imagesloaded.min.js"></script>
<script src="/js/gallery.js"></script>
<script src="/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>











<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/img/scrollup.png"/></a>
	</div>
	<script src="/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
